/* ========================================================================== */
/*   Health.cpp                    		                                      */
/*   (c) 2012 Team 7 Hogeschool Utrecht ICT TI                                */
/*		Lars Stolwijk, Gerben Boot, Guido van Hienen, Marcel Boelen			  */
/*                                                                            */
/*   Responsible for the players health, gives signal when health becomes	  */
/*	 zero or less.														      */
/* ========================================================================== */

#include "Health.h"

void Health::RegisterGameHandler(GameHandler * gameHandler){
	theGameHandler = gameHandler;
	health = 100;
}

void Health::main()
{
	for(;;)
	{
		RTOS::event e = wait( ); 
		if(ResetHealthFlag == e)
		{
			HealthPool.write(health = 100);	
		}
		else if(DecreaseAndGetHealthFlag == e)
		{
			health -= _HITIMPACT;
			if(health < 0)
			{
				health = 0;
			}
			HealthPool.write(health);
			theProcessHitController->HealthPlaced();
			if(health <= 0)	
			{
				theGameHandler->Death();
			}
		}
	}
}

void Health::DecreaseAndGetHealth()
{
	DecreaseAndGetHealthFlag.set();
}

void Health::ResetHealth()
{
	ResetHealthFlag.set();
}

signed char Health::ReadHealth(){
	return HealthPool.read();
}
